package com.secsys.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.secsys.dto.StoFinancecashDTO;
import com.secsys.model.TbStoFinancecash;
import com.secsys.model.TbStoStock;
import com.secsys.service.StoFinanceCashService;
import com.secsys.service.StoStockService;

public class StoFinanceCashServiceImpl extends ServiceImpl<TbStoFinancecash, Integer> implements
		StoFinanceCashService {
	private StoStockService stoStockService;
	
	@Override
	public List<StoFinancecashDTO> queryStoStockdailyByStockCode(int stockCode) {
		TbStoStock tbStoStock=stoStockService.findByProperty("from TbStoStock where stockCode=?", String.valueOf(stockCode)).get(0);
		return queryStoStockdailyByTbStoStock(tbStoStock);
	}

	@Override
	public List<StoFinancecashDTO> queryStoStockdailyByTbStoStock(
			TbStoStock tbStoStock) {
		String hql="from TbStoFinancecash as tsf where tsf.tbStoStock=?";
		return foreachGetDtoFromPojo(this.findByProperty(hql, tbStoStock)); 
	}

	/**
	 * 批量地将持久化对象POJO的List<StoFinancecashDTO>转换成领域对象DTO的List<TbStoFinancecash>
	 * @param List<StoFinancecashDTO>
	 * 			持久化对象POJO的List<StoFinancecashDTO>
	 * @return	List<TbStoFinancecash>
	 * 			领域对象DTO的List<TbStoFinancecash>
	 */
	private List<StoFinancecashDTO> foreachGetDtoFromPojo(List<TbStoFinancecash> tbStoFinancecashList){
		List<StoFinancecashDTO> stoFinancecashDTOList=new ArrayList<StoFinancecashDTO>();
		for (TbStoFinancecash tbStoFinancecash : tbStoFinancecashList) {
			stoFinancecashDTOList.add(getDtoFromPojo(tbStoFinancecash));
		}
		return stoFinancecashDTOList;
	}
	
	/**
	 * 将持久化对象POJO的TbStoFinancecash转换成领域对象DTO的StoFinancecashDTO
	 * @param TbStoFinancecash
	 * 			持久化对象POJO的TbStoFinancecash
	 * @return	StoFinancecashDTO
	 * 			领域对象DTO的StoFinancecashDTO
	 */
	private StoFinancecashDTO getDtoFromPojo(TbStoFinancecash tbStoFinancecash){
		StoFinancecashDTO stoFinancecashDTO=new StoFinancecashDTO(
				tbStoFinancecash.getId(),tbStoFinancecash.getFieldDate(),
				tbStoFinancecash.getSaleRecv(),tbStoFinancecash.getManagementCashNet(),
				tbStoFinancecash.getInvestCashNet(),tbStoFinancecash.getCashNet(),
				tbStoFinancecash.getFinancingtCashNet()
		);
		return stoFinancecashDTO;
	}
	
	public StoStockService getStoStockService() {
		return stoStockService;
	}

	public void setStoStockService(StoStockService stoStockService) {
		this.stoStockService = stoStockService;
	}

	
}
